package org.fu.crowd.service.impl;

import org.fu.crowd.mapper.MemberMapper;
import org.fu.crowd.po.Member;
import org.fu.crowd.po.MemberExample;
import org.fu.crowd.service.api.MemberService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Transactional(readOnly = true)
@Service
public class MemberServiceImpl implements MemberService {

    @Resource
    private MemberMapper memberMapper;


    /**
     *      根据账号查询member
     * @param loginacct
     * @return
     */
    @Override
    public Member getMemberPOByLoginAcct(String loginacct) {
        MemberExample memberExample = new MemberExample();
        memberExample.createCriteria().andLoginacctEqualTo(loginacct);
        List<Member> members = memberMapper.selectByExample(memberExample);
        if (members == null || members.size()==0){
            return null;
        }
        return members.get(0);
    }



    /**
     *      保存注册信息
     */
    @Transactional(propagation = Propagation.REQUIRES_NEW,rollbackFor = Exception.class,readOnly = false)
    @Override
    public void saveMember(Member member) {
        //选择保存，有值的就保存
        memberMapper.insertSelective(member);
    }
}
